<?php
declare (strict_types = 1);

namespace app\home\controller;

use app\home\model\User;
use think\Request;

class Login
{
    public function qqcallback(){
        dd(1);
        require_once ('./Connect2.1/API/qqConnectAPI.php');
        $qc=new \QC();
        $access_token= $qc->qq_callback();
        $openid=$qc->get_openid();
        $qc=new \QC($access_token,$openid);
        $info=$qc->get_user_info();
        $user=User::findUser($openid,"qq");
        $data=[
            'nickname'=>$info['nickname'],
            'open_type'=>'qq',
            'openid'=>$openid,
        ];
        if ($user){
            User::updateUser($data,$user['id']);
        }else{
            User::addUser($data);
        }
    }

    public function finishLogin(){
        $data=\request()->post();
        $res=User::getUser($data);
        if (!$res){
            return fail('账号不存在');
        }
        $password=pwd($data['password']);
        if ($password !=$res['password']){
            return fail('密码错误');
        }
        \think\facade\Session::set('phone',$res['nickname']);
        \think\facade\Session::set('userInfo',$res);
        return success('登录成功');

    }
}
